﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;


namespace Demo
{
    class Program
    {
        static List<Student> list = new List<Student>();
        static Dictionary<int, Student> dictionary = new Dictionary<int, Student>();
        static void Main(string[] args)
        {
            StudentInfo();
           
        }

        private static void StudentInfo()
        {
            Console.WriteLine("请选择：1、添加学生信息。2、查询学生信息");
            int a = int.Parse(Console.ReadLine());
            switch (a)
            {
                case 1://添加学生信息
                    Addstuden();
                    break;
                case 2://查询学生信息
                    Selectstudents();
                    break;

                default:
                    Console.WriteLine("请输入正确的数字");
                    StudentInfo();
                    break;

            }
        }

        private static void Selectstudents()
        {
            Console.WriteLine("1、查询所有（按学号排序）2、查询所有（按姓名排序），3、查询所有（按年龄排序）4、按学号查询（查没有，则打印查无此学生）5、退出");
            int key = int.Parse(Console.ReadLine());
            switch (key)
            {
                case 1://按学号
                    Selectstunum();
                    Selectstudents();
                    break;
                case 2://按姓名
                    Selectstuname();
                    Selectstudents();
                    break;
                case 3://按年龄
                    Selectstuage();
                    Selectstudents();
                    break;
                case 4://按学号   
                    StuID();
                    Selectstudents();
                    break;
                case 5:
                    Environment.Exit(0);
                    break;
                default:
                    Console.WriteLine("请输入正确的数字");
                    Selectstudents();
                    break;
            }
        }

        private static void StuID()
        {
            Console.WriteLine("请输入你要查询的学生的学号：");
            int a = int.Parse(Console.ReadLine());
            if (dictionary.ContainsKey(a))
            {
                Console.WriteLine("学生信息为{0}", dictionary[a]);
            }
            else
            {
                Console.WriteLine("查无此学生！！！");
            }
        }

        private static void Selectstuage()
        {
            list.Sort(new Agesort());
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
        }

        private static void Selectstuname()
        {
            list.Sort(new Namesort());
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
        }

        private static void Selectstunum()
        {
            list.Sort(new Numsort());
            foreach (var item in list)
            {
                Console.WriteLine(item);
            }
        }

        private static void Addstuden()
        {
            Console.WriteLine("请添加学生的学号");
            int newnum = int.Parse(Console.ReadLine());
            Console.WriteLine("请添加学生的姓名");
            string newname = Console.ReadLine();
            Console.WriteLine("请添加学生的年龄");
            int newage = int.Parse(Console.ReadLine());
            Student s1 = new Student(newnum, newname, newage);
            if (dictionary.ContainsKey(newnum))
            {
                Console.WriteLine("请不要输入重复的学号");
                Addstuden();
            } else 
            {
                Console.WriteLine("添加成功！！！");
                dictionary.Add(s1.Num, s1);
                list.Add(s1);
               
            }
            Console.WriteLine("请问需要继续吗？（yes/no）");
            string flag = Console.ReadLine();
            if (flag.Equals("yes"))
            {
                Addstuden();
            }
            else
            {
                StudentInfo();
            }
        }
    }
}
